package com.tang.ack.consumer;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @author fulin.tang
 * 消息接收者
 * 1、@RabbitListener bindings:绑定队列
 * 2、@QueueBinding
 * value:绑定队列的名称、exchange:配置交换器、key:路由键routing-key绑定队列和交换器
 * 3、@Queue value:配置队列名称、autoDelete:是否是一个可删除的临时队列
 * 4、@Exchange value:为交换器起个名称、type:指定具体的交换器类型
 */
@Component
@RabbitListener(bindings = @QueueBinding(
        value = @Queue(value = "${rabbitmq.config.queue.error.name}", autoDelete = "true"),
        exchange = @Exchange(value = "${rabbitmq.config.exchange}", type = ExchangeTypes.DIRECT),
        key = "${rabbitmq.config.queue.error.routing.key}"))
public class LogErrorConsumer {

    /**
     * 接收消息的方法,采用消息队列监听机制.
     *
     * @param msg 接收到的消息
     * @RabbitHandler 意思是将注解@RabbitListener配置到类上面
     * @RabbitHandler 是指定这个方法可以进行消息的接收并且消费.
     */
    @RabbitHandler
    public void consumer(String msg) {
        // 打印消息
        System.out.println("ERROR消费者===>消费<===消息message: " + msg);
        throw new RuntimeException();
    }

}